package main

import (
	"HiChat/models"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
)

func main() {

	dns := "root:123456@tcp(127.0.0.1:3306)/hichat?charset=utf8&parseTime=True&loc=Local"

	db, err := gorm.Open(mysql.Open(dns), &gorm.Config{})
	if err != nil {
		log.Fatal("数据库连接失败", err)
	}

	//err = db.Table("user_basic").AutoMigrate(&models.UserBasic{})
	err = db.AutoMigrate(&models.UserBasic{})
	if err != nil {
		log.Fatal(err)
	}
	log.Printf("创建表成功")

	table := db.Migrator().HasTable(&models.UserBasic{})
	log.Print("表是否存在：", table)

	hasTable := db.Migrator().HasTable("user_basic")

	log.Print("表是否存在：", hasTable)

	//err = db.Migrator().DropTable(&models.UserBasic{})
	//if err != nil {
	//	return
	//}

}
